import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-18
 * Time: 8:50
 */
class Solution9 {

    List<List<Integer>> ret;
    List<Integer> path;
    int n,k;

    public List<List<Integer>> combine(int n1, int k1) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        k = k1;
        n = n1;

        dfs(1);

        return ret;
    }

    void dfs(int pos) {
        if(path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i = pos; i <= n; i++) {
            path.add(i);
            dfs(i+1);
            path.remove(path.size()-1);
        }
    }
}
